home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / graphic import.export / start code / imagesfromurl.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  1.9 KB  |  61 lines

  1. // Graphics Importer and Exporter Samples
  2. // This example creates a URL data reference and opens
  3. // the image from this created reference
  4. // Originally written by Sam Bushell for QuickTime "Live" '99
  5. // WWDC 2000 Introduction to QuickTime
  6.  
  7.  
  8. #include "MacShell.h"
  9.  
  10. void ImageFromURL( void )
  11. {
  12.     OSErr err = noErr;
  13.     DialogPtr dialog;
  14.     short itemHit;
  15.     short itemKind;
  16.     Handle itemHandle;
  17.     Rect itemRect;
  18.     GraphicsImportComponent importer = 0;
  19.     Rect naturalBounds, windowBounds;
  20.     WindowPtr window = NULL;    
  21.     Str255 str;
  22.     Handle urlDataRef = NULL;
  23.     
  24.     // show a dialog and prompt for the URL
  25.     dialog = GetNewDialog( 1006, NULL, (WindowPtr)-1 );
  26.     SetDialogDefaultItem( dialog, kStdOkItemIndex );
  27.     SetDialogCancelItem( dialog, kStdCancelItemIndex );
  28.     SelectDialogItemText( dialog, 3, 0, 1000 );
  29.     ModalDialog( NULL, &itemHit );
  30.     GetDialogItem( dialog, 3, &itemKind, &itemHandle, &itemRect );
  31.     GetDialogItemText( itemHandle, str );
  32.     DisposeDialog( dialog );
  33.     if( kStdCancelItemIndex == itemHit ) return;
  34.     
  35.     // the default URL is
  36.     // "http://www.apple.com/quicktime/developers/icefloe/images/writinguin.gif"
  37.     
  38.     // URL data references must be nul-terminated
  39.     PtrToHand( &str[1], &urlDataRef, 1 + str[0] );
  40.     (*urlDataRef)[ str[0] ] = 0;
  41.     
  42.     // locate and open a graphics importer component for the data reference
  43. // Step 1. Insert ImporterForDataRef.clp here...
  44.     
  45.     // get the native size of the image associated with the importer
  46.     err = GraphicsImportGetNaturalBounds( importer, &naturalBounds );
  47.     
  48.     windowBounds = naturalBounds;
  49.     OffsetRect( &windowBounds, 10, 45 );
  50.     window = NewCWindow( NULL, &windowBounds, "\pImage From URL", true, documentProc, (WindowPtr)-1, true, 0);
  51.     
  52.     // set the graphics port for drawing
  53.     err = GraphicsImportSetGWorld( importer, GetWindowPort( window ), NULL );
  54.  
  55.     // draw the image
  56.     err = GraphicsImportDraw( importer );
  57.     
  58.     CloseComponent( importer );
  59.     DisposeHandle( urlDataRef );
  60. }
  61.